package com.blackhorse.order.feign;

import com.blackhorse.order.entity.Product;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 声明需要调用的微服务名称
 *
 * @FeignClient
 *  name: 服务提供者
 * fallback：配置熔断发生降级方法实现类
 */
@FeignClient(name = "service-product",fallback = ProductFeignClientCallBack.class)
public interface ProductFeignClient {
    /**
     * 配置需要调用的微服务接口
     * 调用这个方法时相当于:
     * String url = "http://service-product/product/{id}";
     * Product product = restTemplate.getForObject(url, Product.class);
     */
    @RequestMapping(path = "/product/{id}", method = RequestMethod.GET)
    Product getProductByFeign(@PathVariable Long id);
}
